package com.sunny.sudy.mq.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.sunny.sudy.mq.entity.OrderInfo;
import com.sunny.sudy.mq.entity.SysConstant;
import com.sunny.sudy.mq.service.MsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: MQController
 * @Description:
 * @Author: sunt
 * @Date: 2020/5/26 18:22
 * @Version 1.0
 **/
@RestController
@RequestMapping("mq")
@Slf4j
public class MQController {

    @Autowired
    private MsgService msgService;

    @GetMapping("sendMsg")
    public String sendMsg() {
        log.info("发送延时消息时间:" + DateUtil.formatDateTime(DateUtil.date()));

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(IdUtil.fastSimpleUUID());
        orderInfo.setOrderState("待支付");
        orderInfo.setPayMoney(999.88);
        msgService.sendDelayMsgToMQ(SysConstant.SYS_ORDER_DELAY_EXCHANGE,SysConstant.SYS_ORDER_DELAY_KEY, JSONUtil.toJsonStr(orderInfo),10*1000);//测试10秒钟
        return JSONUtil.toJsonStr("发送延时消息成功");
    }
}
